# -*- coding: utf-8 -*-
import datetime as datetime
import pandas as pd
import numpy as np
import datetime
import time
from sqlalchemy import create_engine

engine = create_engine('mysql+pymysql://weex:123qwe!!@onlyreaddb.cibzepqty2kl.ap-northeast-1.rds.amazonaws.com:3306/trade_history?charset=utf8')
#engine = engine = create_engine('mysql+pymysql://PP:weex123@192.168.0.196:3306/trade_history?charset=utf8')


##1 sell 2 buy

def balance_history_sql(id):
    sql = """SELECT * FROM deal_history_{} WHERE  time BETWEEN 1535898720 and 1535898900""".format(id)

    return sql


if __name__ == '__main__':
    resufl = []
    df = pd.DataFrame()
    dfname = locals()
    for i in range(0, 100):
        sql = balance_history_sql(i)
        dfname["df{}".format(i)] = pd.read_sql_query(sql, engine)
        resufl.append(dfname["df{}".format(i)])
    data_order = pd.concat(resufl)
    data_order.to_csv("/Users/fiery/Desktop/deal.csv")



